package com.distribution.system.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.distribution.common.core.domain.entity.SysUser;
import com.distribution.common.exception.ServiceException;
import com.distribution.common.utils.DictUtils;
import com.distribution.common.utils.SecurityUtils;
import com.distribution.common.utils.StringUtils;
import com.distribution.system.domain.SysUserRole;
import com.distribution.system.domain.dto.AgentAddDto;
import com.distribution.system.domain.dto.AgentDTO;
import com.distribution.system.domain.dto.CmccDaAccountDetailAddDto;
import com.distribution.system.domain.dto.UpdateSubAgentCommissionByDeductPercentDTO;
import com.distribution.system.domain.entity.*;
import com.distribution.system.mapper.CmccDaProxyProductManageMapper;
import com.distribution.system.mapper.SysUserMapper;
import com.distribution.system.mapper.SysUserRoleMapper;
import com.distribution.system.service.*;
import com.distribution.system.utils.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;

import static com.distribution.common.utils.SecurityUtils.getUserId;
import static com.distribution.common.utils.SecurityUtils.getUsername;

/**
 * @author niejiandeng
 * @date 2023年05月21日 15:25
 */
@Service
@Slf4j
public class AgentManageServiceImpl implements AgentManageService {
    @Resource
    SysUserMapper sysUserMapper;
    @Resource
    private ISysUserService userService;
    @Resource
    CmccDaProxyProductManageService cmccDaProxyProductManageService;
    @Resource
    SysUserRoleMapper sysUserRoleMapper;
    @Resource
    CmccDaCommissionReflectionService cmccDaCommissionReflectionService;
    @Resource
    CmccDaProductService cmccDaProductService;
    @Resource
    CmccDaAccountDetailService cmccDaAccountDetailService;
    @Resource
    CmccDaOrderService cmccDaOrderService;
    @Resource
    CmccDaProxyProductManageMapper cmccDaProxyProductManageMapper;
    @Resource
    FuluUploadPeopleService fuluUploadPeopleService;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addAgent(AgentAddDto agentAddDto) {
        log.info("新增代理入参:{}", JSONObject.toJSONString(agentAddDto));
        Long parentUserId = Objects.isNull(agentAddDto.getParentId()) ? getUserId() : agentAddDto.getParentId();
        String username = getUsername();
        SysUser sysUserAgent = new SysUser();
        BeanUtils.copyProperties(agentAddDto,sysUserAgent);
        if (!userService.checkUserNameUnique(sysUserAgent)) {
            throw new ServiceException("新增用户'" + sysUserAgent.getUserName() + "'失败，登录账号已存在");
        } else if (StringUtils.isNotEmpty(sysUserAgent.getPhoneNumber()) && !userService.checkPhoneUnique(sysUserAgent)) {
            throw new ServiceException("新增用户'" + sysUserAgent.getUserName() + "'失败，手机号码已存在");
        }
        // 获取当前登录用户
        SysUser parentAgent = sysUserMapper.selectUserById(parentUserId);
        log.info("查询用户信息:{}", JSONObject.toJSONString(parentAgent));
        if (parentAgent == null) {
            throw new ServiceException("该用户不存在");
        }
        if (parentAgent.getRoleId() != 100 && parentAgent.getRoleId() != 101 && !parentAgent.isOperationSupervisor()
                && !parentAgent.isAgentOperation() && parentAgent.getRoleId() != 104) {
            throw new ServiceException("该角色【" + parentAgent.getRoleId() + "】不能创建代理账号");
        }

        if (parentAgent.isOperationSupervisor()) {
            sysUserAgent.setRoleId(103L);
        } else if (parentAgent.isAgentOperation() || parentAgent.getRoleId() == 104) {
            sysUserAgent.setRoleId(100L);
        } else if (parentAgent.getRoleId() == 100) {
            sysUserAgent.setRoleId(101L);
        } else if (parentAgent.getRoleId() == 101) {
            sysUserAgent.setRoleId(102L);
        } else {
            throw new ServiceException("该角色不能创建代理账号");
        }
        sysUserAgent.setParentId(parentUserId);
        //代理账号的默认部门为销售中心
        sysUserAgent.setDeptId(101L);
        if (parentAgent.getDeptId() == 102L) {
            sysUserAgent.setDeptId(102L);
        }
        //默认密码为Abc12345.
        if (StringUtils.isEmpty(sysUserAgent.getPassword())) {
            sysUserAgent.setPassword("Abc12345.");
        }
        // 设置了则为设置的密码
        sysUserAgent.setPassword(SecurityUtils.encryptPassword(sysUserAgent.getPassword()));
        // 默认头像
        //sysUserAgent.setAvatar(RuoYiConfig.getAvatarPath() + "/default_avatar.jpg");
        // 设置上级抽成
        sysUserAgent.setSupDeduct(Objects.isNull(agentAddDto.getSupDeduct()) ? parentAgent.getSubDeduct() : agentAddDto.getSupDeduct());
        // 设置下级抽成
        sysUserAgent.setSubDeduct(0.00);
        //添加
        sysUserMapper.insertUser(sysUserAgent);
        log.info("新增用户信息:{}",JSONObject.toJSONString(sysUserAgent));
        SysUserRole sysUserRole = new SysUserRole();
        sysUserRole.setRoleId(sysUserAgent.getRoleId());
        sysUserRole.setUserId(sysUserAgent.getUserId());
        // 新增用户与角色管理
        log.info("新增角色信息:{}",JSONObject.toJSONString(sysUserRole));
        if (sysUserRole.getRoleId() == null || sysUserRole.getUserId() == null) {
            throw new ServiceException("新增角色失败,请稍后再试!");
        }
        sysUserRoleMapper.insertUserRole(sysUserRole);
        log.info("新增角色信息完成:{}",JSONObject.toJSONString(sysUserRole));
        Date date = new Date();
        if (!parentAgent.isOperationSupervisor()) {//总运营相当于开员工账号 无需卡配置
            // 要添加的产品配置信息
            List<CmccDaProxyProductManage> addProxyProductManageList = new ArrayList<>();
            if (parentAgent.isAgentOperation()) {// 代理运营开一级代理账号，需添根据产品信息添加商品配置信息
                String promoteChannel = "0";
                if (sysUserAgent.getDeptId() == 102L) promoteChannel = "1";
                List<CmccDaProduct> list = cmccDaProductService.lambdaQuery()
//                        .eq(CmccDaProduct::getProductStatus, "1")
                        .eq(CmccDaProduct::getPromoteChannel, promoteChannel)
                        .list();
                list.forEach(b->{
                    CmccDaProxyProductManage cmccDaProxyProductManage = new CmccDaProxyProductManage();
                    cmccDaProxyProductManage.setUserId(sysUserAgent.getUserId());
                    cmccDaProxyProductManage.setProductCode(b.getProductCode());
                    cmccDaProxyProductManage.setProductState(Integer.valueOf(b.getProductStatus()));
                    String sysCardStatus = DictUtils.getDictLabel("sys_product_status", String.valueOf(b.getProductStatus()));
                    cmccDaProxyProductManage.setProductStateDesc(sysCardStatus);
                    cmccDaProxyProductManage.setProductCode(b.getProductCode());
                    // 设置佣金(代理运营的下级就是一级代理，没有抽成，直接设置佣金即可)
                    cmccDaProxyProductManage.setCommission(b.getBasicsCommission() != null ? b.getBasicsCommission() : new BigDecimal(0));
                    cmccDaProxyProductManage.setCreateTime(date);
                    cmccDaProxyProductManage.setUpdateTime(date);
                    cmccDaProxyProductManage.setCreateUserId(parentUserId.intValue());
                    cmccDaProxyProductManage.setCreateUserName(username);
                    addProxyProductManageList.add(cmccDaProxyProductManage);
                });
            }else {// 其他的就是一二级代理了
                //查询当前代理所有商品配置信息
                List<CmccDaProxyProductManage> cmccDaProxyProductManageList = cmccDaProxyProductManageService.list(
                        new LambdaQueryWrapper<CmccDaProxyProductManage>().eq(CmccDaProxyProductManage::getUserId, parentUserId));
                // 遍历并添加商品配置信息
                cmccDaProxyProductManageList.forEach(f -> {
                    CmccDaProxyProductManage cmccDaProxyProductManage = new CmccDaProxyProductManage();
                    cmccDaProxyProductManage.setUserId(sysUserAgent.getUserId());
                    cmccDaProxyProductManage.setProductCode(f.getProductCode());
                    cmccDaProxyProductManage.setProductState(f.getProductState());
                    String sysCardStatus = DictUtils.getDictLabel("sys_product_status", String.valueOf(f.getProductState()));
                    cmccDaProxyProductManage.setProductStateDesc(sysCardStatus);
                    cmccDaProxyProductManage.setProductCode(f.getProductCode());
                    // 设置佣金
                    BigDecimal currentCommission = cmccDaProxyProductManageService.getCommissionByDeduct(f.getCommission(), parentAgent.getSupDeduct());
                    cmccDaProxyProductManage.setCommission(currentCommission);
                    cmccDaProxyProductManage.setCreateTime(date);
                    cmccDaProxyProductManage.setUpdateTime(date);
                    cmccDaProxyProductManage.setCreateUserId(parentUserId.intValue());
                    cmccDaProxyProductManage.setCreateUserName(username);
                    addProxyProductManageList.add(cmccDaProxyProductManage);
                });
            }
            if (!addProxyProductManageList.isEmpty()) {
                cmccDaProxyProductManageService.saveBatch(addProxyProductManageList);
//                List<List<CmccDaProxyProductManage>> partition = ListUtils.partition(addProxyProductManageList, 500);
//                partition.forEach(p -> cmccDaProxyProductManageService.saveBatch(p));
            }
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delAgentByUserId(Long userId){
        sysUserMapper.deleteUserById(userId);
        cmccDaProxyProductManageMapper.deleteByUserId(userId);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateAgent(AgentDTO agentDTO) {
        String username = getUsername();
        // 获取目标代理详细信息
        SysUser targetAgent = sysUserMapper.selectUserById(agentDTO.getUserId());
        // 获取当前上级代理信息
        SysUser parentAgent = sysUserMapper.selectUserById(getUserId());
        // 修改代理联系电话
        if (!StringUtils.equals(agentDTO.getPhoneNumber(), targetAgent.getPhoneNumber()) && !parentAgent.isOperationSupervisor()){
            throw new ServiceException("为保障您的资金安全，修改联系电话请联系平台客服");
        }
        targetAgent.setPhoneNumber(agentDTO.getPhoneNumber());
        // 只有运营账号有权限修改登录账号和代理佣金
        if (parentAgent.isOperationSupervisor()){
            if (!StringUtils.equals(targetAgent.getUserName(), agentDTO.getUserName())) {
                // 修改代理账号
                SysUser user = sysUserMapper.selectUserByUserName(agentDTO.getUserName());
                if (user != null) throw new ServiceException("登录账号【" + user.getUserName() + "】已存在！");
                targetAgent.setUserName(agentDTO.getUserName());
                // 认证信息中修改代理账号
                fuluUploadPeopleService.lambdaUpdate().eq(FuluUploadPeople::getUserId, targetAgent.getUserId())
                        .set(FuluUploadPeople::getAccount, agentDTO.getUserName())
                        .update();
            }
            // 修改代理佣金
            int compared = targetAgent.getCommission().compareTo(agentDTO.getCommission());
            if (compared < 0) throw new ServiceException("暂不支持给代理增加佣金！");
            if (compared > 0){
                CmccDaAccountDetailAddDto cmccDaAccountDetailAddDto = new CmccDaAccountDetailAddDto();
                cmccDaAccountDetailAddDto.setSysUser(targetAgent);
                cmccDaAccountDetailAddDto.setDetailType("3");
                cmccDaAccountDetailAddDto.setFrontAmount(targetAgent.getCommission());
                cmccDaAccountDetailAddDto.setChangeAmount(targetAgent.getCommission().subtract(agentDTO.getCommission()));
                cmccDaAccountDetailAddDto.setAfterAmount(agentDTO.getCommission());
                // 修改代理佣金
                targetAgent.setCommission(cmccDaAccountDetailAddDto.getAfterAmount());
                // 添加资金明细
                cmccDaAccountDetailService.addAccountDetail(cmccDaAccountDetailAddDto);
            }
        }
        if (!targetAgent.getNickName().equals(agentDTO.getNickName())) {
            cmccDaAccountDetailService.lambdaUpdate().set(CmccDaAccountDetail::getUserName,agentDTO.getNickName()).eq(CmccDaAccountDetail::getUserId,agentDTO.getUserId()).update();
            cmccDaCommissionReflectionService.lambdaUpdate().set(CmccDaCommissionReflection::getCreateUserName,agentDTO.getNickName()).eq(CmccDaCommissionReflection::getCreateUserId,agentDTO.getUserId()).update();
            cmccDaOrderService.lambdaUpdate().set(CmccDaOrder::getUserName,agentDTO.getNickName()).eq(CmccDaOrder::getUserId,agentDTO.getUserId()).update();
        }
        if (StringUtils.isNotEmpty(agentDTO.getPassword())) {
            targetAgent.setPassword(SecurityUtils.encryptPassword(agentDTO.getPassword()));
        }
        // 修改下级抽成
        Double setSupDeduct = agentDTO.getSupDeduct();
        if (Objects.nonNull(setSupDeduct) && !setSupDeduct.equals(targetAgent.getSupDeduct())){
            List<Long> roleList = Arrays.asList(101L, 102L);// 只有二三级代理可以被上级单独设置抽成百分比
            if (!roleList.contains(targetAgent.getRoleId())) throw new ServiceException("当前代理无法被抽佣金");
            if (setSupDeduct < 0) throw new ServiceException("佣金抽成不能为负数");
            // 抽成差
            Double supDeduct = targetAgent.getSupDeduct() == null ? 0 : targetAgent.getSupDeduct();
            BigDecimal deductDiff = BigDecimal.valueOf(setSupDeduct - supDeduct);
            if (deductDiff.compareTo(BigDecimal.ZERO) != 0){
                // 设置代理上级抽成
                targetAgent.setSupDeduct(setSupDeduct);
                // 查上级
                SysUser superSysUser = sysUserMapper.selectUserById(targetAgent.getParentId());
                List<CmccDaProxyProductManage> superProxyCardManageList = cmccDaProxyProductManageService.list(new LambdaQueryWrapper<CmccDaProxyProductManage>()
                        .eq(CmccDaProxyProductManage::getUserId, superSysUser.getUserId()));
                // 查询当前用户所有产品信息
                List<CmccDaProxyProductManage> cmccDaProxyCardManageList = cmccDaProxyProductManageService.list(new LambdaQueryWrapper<CmccDaProxyProductManage>()
                        .eq(CmccDaProxyProductManage::getUserId, targetAgent.getUserId()));
                cmccDaProxyCardManageList.forEach(m -> {
                    // 修改代理的产品佣金
                    CmccDaProxyProductManage cmccDaProxyProductManage = superProxyCardManageList.stream()
                            .filter(f -> StringUtils.equals(f.getProductCode(), m.getProductCode())).collect(Collectors.toList()).get(0);
                    // 抽成
                    BigDecimal currentCommission = cmccDaProxyProductManageService.getCommissionByDeduct(cmccDaProxyProductManage.getCommission(), setSupDeduct);
                    if (m.getCommission().compareTo(currentCommission) != 0) {
                        m.setCommission(currentCommission);
                        cmccDaProxyProductManageService.updateById(m);
                        // 更新所有下级卡配置信息
                        UpdateSubAgentCommissionByDeductPercentDTO updateSubAgentCommissionByDeductPercentDTO = new UpdateSubAgentCommissionByDeductPercentDTO();
                        updateSubAgentCommissionByDeductPercentDTO.setCurrentSysUser(targetAgent);
                        updateSubAgentCommissionByDeductPercentDTO.setProductCode(m.getProductCode());
                        updateSubAgentCommissionByDeductPercentDTO.setMyCommission(m.getCommission());
                        cmccDaProxyProductManageService.updateSubAgentCommissionByDeductPercent(updateSubAgentCommissionByDeductPercentDTO);
                    }
                });
            }
        }
        targetAgent.setNickName(agentDTO.getNickName());
        targetAgent.setRemark(agentDTO.getRemark());
        targetAgent.setUpdateBy(username);
        targetAgent.setUpdateTime(new Date());
        userService.updateUser(targetAgent);
    }

    @Override
    public void unbindWeChat(SysUser sysUser) {
//        SysUser sysUser2 = sysUserMapper.selectUserById(getUserId());
//        if (!sysUser2.isOperationSupervisor()) {
//            throw new ServiceException("该角色没有解绑权限!");
//        }
        SysUser sysUser1 = sysUserMapper.selectUserById(sysUser.getUserId());
        if (sysUser1.getOpenId() == null) {
            throw new ServiceException("未绑定微信无需解绑!");
        }
        sysUserMapper.unbindWeChat(sysUser.getUserId());
    }

    @Override
    public List<SysUser> selectAgent(AgentDTO agentDTO,SysUser sysUser) {
        agentDTO.setRoleId(sysUser.getRoleId());
        Long userId = getUserId();
        List<SysUser> sysUsers;
        agentDTO.setParentId(userId);
        sysUsers = userService.selectUserListByParentIdWithPage(agentDTO);
        /*//总运营 代理运营 管理员看全部
        if (sysUser.isOperationSupervisor() || sysUser.isAdmin() || sysUser.isAgentOperation()) {
            agentDTO.setParentId(userId);
            sysUsers = sysUserMapper.selectAllUserListByParentId(agentDTO);
        } else {
            //代理运营看各自
            agentDTO.setParentId(userId);
            sysUsers = sysUserMapper.selectUserListByParentId(agentDTO);
        }*/
        return sysUsers;
    }

    @Override
    public SysUser getMyInfo(Long postId) {
        SysUser sysUser = sysUserMapper.selectUserById(postId);
        // 已成功订单数量
        Integer success = cmccDaOrderService.lambdaQuery().eq(CmccDaOrder::getUserId, sysUser.getUserId()).eq(CmccDaOrder::getOrderStatus, "3").count();
        sysUser.setSuccessOrderCount(success);
        // 进行中订单数量
        Integer process = cmccDaOrderService.lambdaQuery().eq(CmccDaOrder::getUserId, sysUser.getUserId()).eq(CmccDaOrder::getOrderStatus, "2").count();
        sysUser.setProcessOrderCount(process);
        // 下级代理数量
        AgentDTO agentDTO = new AgentDTO();
        agentDTO.setParentId(sysUser.getUserId());
//        int agentCount = sysUserMapper.selectAllUserListByParentId(agentDTO).size();
        int agentCount = userService.selectUserListByParentId(agentDTO).size();
        sysUser.setAgentCount(agentCount);
        // 查找近期的提现记录
        CmccDaCommissionReflection cmccDaCommissionReflection = cmccDaCommissionReflectionService.getOne(new LambdaQueryWrapper<CmccDaCommissionReflection>()
                .eq(CmccDaCommissionReflection::getCreateUserId, postId)
                .orderByAsc(CmccDaCommissionReflection::getCreateTime)
                .last("limit 1"));
        // 查找资金明细
        List<CmccDaAccountDetail> cmccDaAccountDetails = cmccDaAccountDetailService.list(new LambdaQueryWrapper<CmccDaAccountDetail>()
                .eq(CmccDaAccountDetail::getUserId, postId)
                .eq(CmccDaAccountDetail::getOrderStatus, 1)
                .and(a -> a.in(CmccDaAccountDetail::getDetailType, 0,1).or().isNull(CmccDaAccountDetail::getDetailType)));
        // 累计收益
        BigDecimal totalAmount = cmccDaAccountDetails.stream()
                // 将user对象的age取出来map为Bigdecimal
                .map(CmccDaAccountDetail::getChangeAmount)
                // 使用reduce()聚合函数,实现累加器
                .reduce(BigDecimal.ZERO, BigDecimal::add);
        sysUser.setTotalAmount(totalAmount.setScale(2, RoundingMode.HALF_UP));
        // 今日收益
        Date start = DateUtil.strToDateLong(DateUtil.dateToStr(new Date(), Locale.CHINA) + " 00:00:00");
        Date end = DateUtil.strToDateLong(DateUtil.dateToStr(new Date(), Locale.CHINA) + " 23:59:59");
        List<CmccDaAccountDetail> cmccDaAccountDetailsToday = cmccDaAccountDetailService.list(new LambdaQueryWrapper<CmccDaAccountDetail>()
                .eq(CmccDaAccountDetail::getUserId, postId)
                .eq(CmccDaAccountDetail::getOrderStatus, 1)
                .ge(CmccDaAccountDetail::getUpdateTime, start)
                .le(CmccDaAccountDetail::getUpdateTime, end)
                .and(a -> a.in(CmccDaAccountDetail::getDetailType, 0,1).or().isNull(CmccDaAccountDetail::getDetailType)));
        BigDecimal todayAmount = cmccDaAccountDetailsToday.stream().map(CmccDaAccountDetail::getChangeAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
        sysUser.setTodayAmount(todayAmount.setScale(2, RoundingMode.HALF_UP));
        // 查找提现记录
        List<CmccDaCommissionReflection> list = cmccDaCommissionReflectionService.list(new LambdaQueryWrapper<CmccDaCommissionReflection>()
                .eq(CmccDaCommissionReflection::getCreateUserId, postId)
                .eq(CmccDaCommissionReflection::getReflectionState, 1));
        // 提现中中金额
        BigDecimal reflectionAmounting = list.stream().map(CmccDaCommissionReflection::getReflectionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
        sysUser.setReflectionAmounting(reflectionAmounting.setScale(2, RoundingMode.HALF_UP));
        if (cmccDaCommissionReflection != null ) {
            sysUser.setReflectionAccountName(cmccDaCommissionReflection.getReflectionAccountName());
            sysUser.setReflectionAccount(cmccDaCommissionReflection.getReflectionAccount());
        }
        return sysUser;
    }

    /**
     * @Author: GodLu
     * @Date: 2024/5/13 17:39
     * @Description: 修改用户下级抽成
     * @param subDeduct 下级抽成
     * @return: void
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void setSubDeduct(Double subDeduct) {
        if (subDeduct == null) throw new ServiceException("佣金抽成不能为空");
        if (subDeduct < 0) throw new ServiceException("佣金抽成不能小于零");
        SysUser currentUser = sysUserMapper.selectUserById(getUserId());
        // 超级管理员、总运营、代理运营没有权限根据下级佣金百分比更新所有下级所有卡配置佣金
        if (currentUser.getRoleId() == 1 || currentUser.isOperationSupervisor() || currentUser.isAgentOperation()){
            throw new ServiceException("当前用户不能设置下级佣金抽成");
        }
        if (currentUser.getSubDeduct() != null && subDeduct.compareTo(currentUser.getSubDeduct()) == 0) return;
        // 更新当前用户信息
        currentUser.setSubDeduct(subDeduct);
        currentUser.setUpdateBy(getUsername());
        currentUser.setUpdateTime(new Date());
        sysUserMapper.updateUser(currentUser);
        // 更新下一级代理信息
        AgentDTO agentDTO = new AgentDTO();
        agentDTO.setParentId(getUserId());
//        List<SysUser> sysUserList = sysUserMapper.selectUserListByParentId(agentDTO);
        List<SysUser> sysUserList = userService.selectUserListByParentId(agentDTO);
        for (SysUser user : sysUserList) {
            user.setSupDeduct(subDeduct);
            sysUserMapper.updateUser(user);
        }
        // 查询当前用户所有产品信息
        List<CmccDaProxyProductManage> cmccDaProxyCardManageList = cmccDaProxyProductManageService.list(new LambdaQueryWrapper<CmccDaProxyProductManage>()
                .eq(CmccDaProxyProductManage::getUserId, currentUser.getUserId()));
        cmccDaProxyCardManageList.forEach(m -> {
            // 更新所有下级卡配置信息
            UpdateSubAgentCommissionByDeductPercentDTO updateSubAgentCommissionByDeductPercentDTO = new UpdateSubAgentCommissionByDeductPercentDTO();
            updateSubAgentCommissionByDeductPercentDTO.setCurrentSysUser(currentUser);
            updateSubAgentCommissionByDeductPercentDTO.setProductCode(m.getProductCode());
            updateSubAgentCommissionByDeductPercentDTO.setMyCommission(m.getCommission());
            cmccDaProxyProductManageService.updateSubAgentCommissionByDeductPercent(updateSubAgentCommissionByDeductPercentDTO);
        });
    }
}
